const http = require('../../../utils/http');
Page({
  data: {
    showButtonView: false,
    option: {
      Url: '',
      Path: '',
      Title: '',
      Description: '',
      Imgurl: ''
    },
    backIcon: 'http://oss.myzy.com.cn/wechat/images/goback.png',
    homeIcon: ''
  },
  _onShowModal() {
    if (!wx.getStorageSync('token')) {
      wx.navigateTo({
        url: '/pages/Login/Index/index',
      })
    } else {
      this.setData({
        showButtonView: !this.data.showButtonView
      })
    }
  },
  onKefu(){
    this.setData({
      showButtonView: !this.data.showButtonView
    })
  },
  onLoad: function (options) {
    console.log(options)
    var _this = this
    _this.setData({
      homeIcon: options.cards ? 'https://huixuangou.oss-cn-beijing.aliyuncs.com/wechat/Xz_MiNi_image/home_tab_icon_home_def%402x.png' : '',
      backIcon: options.cards ? '' : 'http://oss.myzy.com.cn/wechat/images/goback.png',
      cardImg:wx.getStorageSync('v1/user').data.subscribe.kefu.link.image
    })
    if (options.cards) {
      var info = JSON.parse(options.cards)
      _this.setData({
        option: encodeURIComponent(JSON.stringify({
          userinfo: {
            nickName: info.nickName,
            avatarUrl: info.avatarUrl
          },
          keyword:'公众号',
          ctag: info.ctag
        })),
        cardImg:info.cardImg,
        title:options.title?options.title : '关注公众号'
      })
      console.log(info, encodeURIComponent(JSON.stringify({
        userinfo: {
          nickName: info.nickName,
          avatarUrl: info.avatarUrl
        },
        keyword:info.keyword,
        ctag: info.ctag
      })))
    } else {
      _this.setData({
        option: options.card,
        title:options.title
      })
      console.log(encodeURI(options.card))
    }
    http.getRequest('v1/user', {},
      function (res) {},
      function (err) {
        wx.removeStorageSync('member')
        wx.removeStorageSync('token')
      })
  },
  News() {
    this.setData({
      showButtonView: !this.data.showButtonView
    })
    wx.navigateTo({
      url: '/pages/onNewPages/my_chat/chat/chat?card=' + this.data.option,
    })
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {}
})